package cn.gson.fengboot.controller;

import cn.gson.fengboot.model.pojos.Zchuku;
import cn.gson.fengboot.model.pojos.Zchukuxq;
import cn.gson.fengboot.model.pojos.Zinvoice;
import cn.gson.fengboot.model.pojos.Zruku;
import cn.gson.fengboot.model.service.ZchukuService;
import cn.gson.fengboot.model.service.ZinvoiceService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/chuku")
public class ZchukuController {
    @Autowired
    ZchukuService service;

    //出库查询方法
    @RequestMapping("/list_chuku")
    @ResponseBody
    public Map<String, Object> kaipiao(Integer page, Integer size, String search, String search2) {
        Page<Object> obj = PageHelper.startPage(page, size);
        service.chukuliebiao(search,search2);

        Map<String, Object> map = new HashMap<>();
        map.put("total", obj.getTotal());
        map.put("rows", obj.getResult());
        return map;
    }

    //出库弹框方法
    @RequestMapping("/list_chukutk")
    @ResponseBody
    public Map<String, Object> chukutk(Integer page, Integer size, String search, String search2) {
        Page<Object> obj = PageHelper.startPage(page, size);
        service.chukutk(search,search2);

        Map<String, Object> map = new HashMap<>();
        map.put("total", obj.getTotal());
        map.put("rows", obj.getResult());
        return map;
    }

    //出库弹框方法
    @RequestMapping("/list_chukutk2")
    @ResponseBody
    public Map<String, Object> chukutk2(Integer page, Integer size, String search, String search2) {
        Page<Object> obj = PageHelper.startPage(page, size);
        service.chukutk2(search,search2);

        Map<String, Object> map = new HashMap<>();
        map.put("total", obj.getTotal());
        map.put("rows", obj.getResult());
        return map;
    }

    //出库详情方法
        @RequestMapping("/list_chukuxq")
    @ResponseBody
    public List<Zchukuxq> chukuxq(Integer search) {


        return service.chukuxq(search);
    }

    //出库详情方法
    @RequestMapping("/list_chukuxq2")
    @ResponseBody
    public Map<String, Object> chukuxq2(Integer page, Integer size, String search, String search2) {
        Page<Object> obj = PageHelper.startPage(page, size);
        service.chukuxq2(search,search2);

        Map<String, Object> map = new HashMap<>();
        map.put("total", obj.getTotal());
        map.put("rows", obj.getResult());
        return map;
    }

    //出库单新增修改
    @RequestMapping("/add")
    @ResponseBody
    public void add(@RequestBody Zchuku ck){
        service.add(ck);
    }
}
